$(() => {
  $(".action .book").on("click",function () {
  let roomName= $(this).closest('li').find('h2').text();
  let birthFrom=$(this).closest('li').find(".birthFrom").val();
  let birthTo=$(this).closest('li').find(".birthTo").val();
  if(birthFrom>birthTo){
    alert("入住日期不能大于离店日期")
    return
  }

  if(birthFrom.length===0&&birthTo.length===0){
    alert("入住日期和离店日期都不能为空")
    return
  }

  // 调用book方法
  //使用获取到的房间名发送ajax请求
  $.ajax({
    url: ctx + "/client/book",
    method: "post",
    dataType: "json",
    data: {
      roomName,
      birthFrom,
      birthTo
    },
    success(resp) {
      if (resp.success) {
        alert("预约成功");
      }else{
        alert("预约失败")
      }
    },
    error(resp) {
      if (resp.status === 401) {
        location.href = ctx + "/client/login";
      }
    }
  });

    
})


});